import { Column, Entity, JoinColumn, TreeChildren, TreeParent } from 'typeorm';
import { BaseEntity } from './BaseEntity';

@Entity({
  orderBy: {
    sort: 'ASC',
    createTime: 'DESC'
  }
})
export class SysMenu extends BaseEntity {
  @Column({
    type: 'varchar',
    nullable: true,
    comment: '备注'
  })
  remark: string;

  @TreeChildren()
  children: SysMenu[];

  @TreeParent({
    onDelete: 'CASCADE'
  })
  @JoinColumn({
    name: 'parent_id'
  })
  parent: SysMenu;

  @Column({
    type: 'varchar',
    nullable: true,
    comment: '图标'
  })
  icon: string;

  @Column({
    type: 'varchar',
    nullable: true,
    comment: '路径'
  })
  link: string;

  @Column({
    type: 'varchar',
    nullable: true,
    comment: '遵循RESTFULL接口'
  })
  api: string;

  @Column({
    type: 'varchar',
    comment: '名称'
  })
  text: string;

  @Column({
    type: 'varchar',
    nullable: true,
    comment: '嵌套链接'
  })
  frame: string;

  @Column({
    type: 'varchar',
    nullable: true,
    unique: true,
    comment: '路由链接'
  })
  router: string;

  @Column({
    type: 'varchar',
    nullable: true,
    comment: '路由路径'
  })
  path: string;

  @Column({
    type: 'varchar',
    nullable: true,
    comment: '标题'
  })
  title: string;

  @Column({
    type: 'boolean',
    nullable: true,
    default: false,
    name: 'keep_alive',
    comment: '路由缓存'
  })
  keepAlive: boolean;

  @Column({
    type: 'varchar',
    nullable: true,
    default: 'ROUTER',
    comment: '路由模式'
  })
  moda: string;

  @Column({
    type: 'boolean',
    default: false,
    name: 'hide_in_breadcrumb',
    comment: '是否显示面包屑'
  })
  hideInBreadcrumb: string;

  @Column({
    type: 'boolean',
    comment: '是否禁用菜单',
    default: false
  })
  forbidden: boolean;

  @Column({
    type: 'boolean',
    comment: '是否叶子菜单',
    name: 'is_leaf',
    default: false
  })
  isLeaf: boolean;

  @Column({
    type: 'boolean',
    comment: '是否显示展开',
    name: 'show_expand',
    default: false
  })
  showExpand: boolean;

  @Column({
    type: 'int',
    comment: '序号'
  })
  sort: number;
}
